import { delDictData, listDictData } from "@/api/service/dict/data/dict.data";
import { currentDictType, form, resetForm, showForm } from "./form";
import { keys, query, table } from "./table";

export const list = async () => {
  table.value.loading = true;
  const data = await listDictData(query.value);
  table.value.data = data.rows;
  query.value.total = data.total;
  table.value.loading = false;
};

export const edit = async (record?: DictData) => {
  form.value = record!;

  showForm.value = true;
};
export const create = async () => {
  resetForm();
  form.value.dictType = `${currentDictType.value}`;
  showForm.value = true;
};
export const del = async (id?: string) => {
  const targetId = [id];
  await delDictData(`${targetId}`);
  await list();
  keys.value = [];
};

export const search = () => {
  query.value.pageNum = 1;
  list();
};
